<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Apiall extends FOX_Controller {

	function __construct ()
	{
		parent::__construct();
		$this->load->library('form_validation');
	}
	
	public function qq()
	{
		$city = str_replace('市','',$this->input->post('city'));
		$lat = $this->input->post('lat');
		$lng = $this->input->post('lng');
		$addr = $this->input->post('addr');
		$machine_key = $this->USER_KEY;
		if($machine_key && $city && $lat && $lng){			
			if(!$this->guest_m->get_guest_by_machine_key($machine_key)){
				$str = array(
					'machine_key' => $machine_key,
					'guest_city' => $city,
					'guest_lat' => $lat,
					'guest_lng' => $lng,
					'guest_addr' => $addr,
					'guest_add_time' => time(),
				);
				$this->guest_m->add_guest($str);
			}else{
				$str = array(
					'guest_city' => $city,
					'guest_lat' => $lat,
					'guest_lng' => $lng,
					'guest_addr' => $addr,
					'guest_add_time' => time(),
				);
				$this->guest_m->update_guest($machine_key,$str);
			}
		}
	}

	public function guest()
	{
		$city = str_replace('市','',$this->input->post('city'));
		$lat = $this->input->post('lat');
		$lng = $this->input->post('lng');
		$addr = $this->input->post('addr');
		$uuid = $this->input->post('uuid');
		if($uuid && $city && $lat && $lng){			
			if(!$guest = $this->guest_m->get_guest_by_machine_key($uuid)){
				$str = array(
					'machine_key' => $uuid,
					'guest_city' => $city,
					'guest_lat' => $lat,
					'guest_lng' => $lng,
					'guest_addr' => $addr,
					'guest_add_time' => time(),
				);
				$this->guest_m->add_guest($str);
			}else if(time()-$guest['guest_add_time']>3600){
				$str = array(
					'guest_city' => $city,
					'guest_lat' => $lat,
					'guest_lng' => $lng,
					'guest_addr' => $addr,
					'guest_add_time' => time(),
				);
				$this->guest_m->update_guest($uuid,$str);
			}
		}
		echo json_encode(['status' => 0, 'msg' => '发送成功']);exit();
	}
	
}
